home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / daemons / migd / RCS / migPdev.c,v < prev    next >
Encoding:
Text File  |  1990-07-05  |  35.5 KB  |  1,508 lines

  1. head     2.1;
  2. branch   ;
  3. access   ;
  4. symbols  before_fairness_changes:2.0 ckpt1:1.3;
  5. locks    ; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 2.1
  10. date     90.07.05.13.19.38;  author douglis;  state Exp;
  11. branches ;
  12. next     2.0;
  13.  
  14. 2.0
  15. date     90.06.30.17.09.21;  author douglis;  state Stable;
  16. branches ;
  17. next     1.9;
  18.  
  19. 1.9
  20. date     90.05.28.17.07.27;  author douglis;  state Exp;
  21. branches ;
  22. next     1.8;
  23.  
  24. 1.8
  25. date     90.05.02.12.31.27;  author douglis;  state Exp;
  26. branches ;
  27. next     1.7;
  28.  
  29. 1.7
  30. date     90.04.27.00.59.18;  author douglis;  state Exp;
  31. branches ;
  32. next     1.6;
  33.  
  34. 1.6
  35. date     90.04.24.18.00.41;  author douglis;  state Exp;
  36. branches ;
  37. next     1.5;
  38.  
  39. 1.5
  40. date     90.04.03.11.09.35;  author douglis;  state Exp;
  41. branches ;
  42. next     1.4;
  43.  
  44. 1.4
  45. date     90.03.14.12.49.57;  author douglis;  state Exp;
  46. branches ;
  47. next     1.3;
  48.  
  49. 1.3
  50. date     90.03.12.13.45.47;  author douglis;  state Exp;
  51. branches ;
  52. next     1.2;
  53.  
  54. 1.2
  55. date     90.02.28.10.50.24;  author douglis;  state Exp;
  56. branches ;
  57. next     1.1;
  58.  
  59. 1.1
  60. date     90.02.15.19.19.06;  author douglis;  state Exp;
  61. branches ;
  62. next     ;
  63.  
  64.  
  65. desc
  66. @Routines to manage pseudo-devices for the migration daemon.
  67. This is also the only file that deals with byte ordering issues.
  68. @
  69.  
  70.  
  71. 2.1
  72. log
  73. @nothing major.
  74. @
  75. text
  76. @/* 
  77.  * migPdev.c --
  78.  *
  79.  *    Routines to manage pseudo-devices for the migration daemon.
  80.  *    This is also the only file that deals with byte ordering issues.
  81.  *
  82.  *    Most operations are done using ioctls.  Reads and writes are used
  83.  *     for the following purpose:
  84.  *
  85.  *    - the loadavg daemons write load vectors asynchronously,
  86.  *    - user processes can read load vectors for their own host
  87.  *      (synchronously), and
  88.  *    - user processes can select on the pdev to find out about changes
  89.  *      in the state of idle hosts (new ones available or ones being
  90.  *      reclaimed).
  91.  *
  92.  * Copyright 1989, 1990 Regents of the University of California
  93.  * Permission to use, copy, modify, and distribute this
  94.  * software and its documentation for any purpose and without
  95.  * fee is hereby granted, provided that the above copyright
  96.  * notice appear in all copies.  The University of California
  97.  * makes no representations about the suitability of this
  98.  * software for any purpose.  It is provided "as is" without
  99.  * express or implied warranty.
  100.  */
  101.  
  102. #ifndef lint
  103. static char rcsid[] = "$Header: /sprite/src/daemons/migd/RCS/migPdev.c,v 2.0 90/06/30 17:09:21 douglis Stable Locker: douglis $ SPRITE (Berkeley)";
  104. #endif /* not lint */
  105.  
  106. #include <sprite.h>
  107. #include <string.h>
  108. #include <errno.h>
  109. #include <status.h>
  110. #include "syslog.h"
  111. #include <bstring.h>
  112. #include <fs.h>
  113. #include <kernel/fs.h>
  114. #include <sys/types.h>
  115. #include <unistd.h>
  116. #include <stdlib.h>
  117. #include <stdio.h>
  118. #include <sys/dir.h>
  119. #include <sys/stat.h>
  120. #include <host.h>
  121. #include <pdev.h>
  122. #include <fmt.h>
  123. #include "migd.h"
  124. #include "migPdev.h"
  125. #include "global.h"
  126.  
  127.  
  128. static int        PdevOpen(), PdevClose(), PdevWrite();
  129. static int        PdevRead(), PdevIoctl();
  130.  
  131. static Pdev_CallBacks    service = {
  132.                 PdevOpen,    /* open */
  133.                 PdevRead,    /* read */
  134.                 PdevWrite,    /* write */
  135.                 PdevIoctl,    /* ioctl */
  136.                 PdevClose,    /* close */
  137.                 NULL, NULL    /* get/set attr */
  138.             };
  139.  
  140. typedef struct {
  141.     int (*routine)();        /* routine to call */
  142.     char *inFmt;        /* string to pass to Fmt_Convert for input */
  143.     char *outFmt;        /* string to pass to Fmt_Convert for output */
  144. } IoctlCallback;
  145.  
  146.     
  147. /*
  148.  * Define fmt conversions for the structures in mig.h.  This is only used
  149.  * here and is separated from the structures because users need not be
  150.  * aware of conversion issues.
  151.  *                                    *
  152.  ********************************************************************
  153.  *                   IMPORTANT NOTE                 *
  154.  ********************************************************************
  155.  *                                    *
  156.  * Changes to the structures in mig.h must also be reflected below. *
  157.  *                                    *
  158.  ********************************************************************
  159.  */
  160.  
  161. /*
  162.  * The Mig_LoadVector is imbedded in a Mig_Info.  With old compilers
  163.  * we can't concatenate anyway.
  164.  */
  165. #define MIGD_LOADVEC_FMT "{w8d3}"
  166. #define MIGD_INFO_FMT "{w12{w8d3}}"
  167. #define MIGD_UP_IN_FMT MIGD_INFO_FMT
  168.  
  169. #define MIGD_GETINFO_IN_FMT "{w2}"
  170. #ifdef __STDC__
  171. #define MIGD_GETINFO_OUT_FMT "w2" MIGD_INFO_FMT "*"
  172. #else /* __STDC__ */
  173. #define MIGD_GETINFO_OUT_FMT "w2{w12{w8d3}}*"
  174. #endif /* __STDC__ */
  175.  
  176.  
  177. #define MIGD_GETIDLE_IN_FMT "{w4}"
  178. #define MIGD_GETIDLE_OUT_FMT "w*"
  179.  
  180.  
  181.  
  182. #define MIGD_DONE_IN_FMT "w*"
  183. #define MIGD_REMOVE_IN_FMT MIGD_DONE_IN_FMT
  184.  
  185. #define MIGD_CHANGE_IN_FMT "w"
  186. #define MIGD_PARAMS_FMT "{w4d2}"
  187. #define MIGD_STATS_FMT "{w12{b12w45{w20}2}8}"
  188. #define MIGD_GET_UPDATE_OUT_FMT "w"
  189. #define MIGD_EVICT_OUT_FMT "w"
  190.  
  191. /* 
  192.  * When a  daemon starts up, it does an ioctl with a full Mig_Info to
  193.  * start things off.  Then it does writes with new load vectors, and
  194.  * ioctls to flag special cases such as eviction.
  195.  */
  196. #define MIGD_DAEMON_IN_FMT MIGD_INFO_FMT
  197.  
  198. static IoctlCallback ioctlCallbacks[] = {
  199.     { Global_GetLoadInfo,     MIGD_GETINFO_IN_FMT, MIGD_GETINFO_OUT_FMT}, 
  200.     { Global_GetIdle,         MIGD_GETIDLE_IN_FMT, MIGD_GETIDLE_OUT_FMT}, 
  201.     { Global_DoneIoctl,        MIGD_DONE_IN_FMT, (char *) NULL}, 
  202.     { Global_RemoveHost,     MIGD_REMOVE_IN_FMT, (char *) NULL},
  203.     { Global_HostUp,         MIGD_UP_IN_FMT, (char *) NULL},
  204.     { Global_ChangeState,    MIGD_CHANGE_IN_FMT, (char *) NULL},
  205.     { Migd_GetParms,        (char *) NULL, MIGD_PARAMS_FMT},
  206.     { Migd_SetParms,        MIGD_PARAMS_FMT, (char *) NULL},
  207.     { Global_GetStats,        (char *) NULL, MIGD_STATS_FMT},
  208.     { Global_GetUpdate,        (char *) NULL, MIGD_GET_UPDATE_OUT_FMT},
  209.     { Migd_EvictIoctl,        (char *) NULL, MIGD_EVICT_OUT_FMT},
  210.     { Global_ResetStats,    (char *) NULL, (char *) NULL},
  211. };
  212.  
  213. /*
  214.  * Pdev identifier for the master end of the pdev, when open.
  215.  */
  216. static Pdev_Token    pdev = (Pdev_Token) NULL;
  217.  
  218. static char *pdevName;            /* File name of the pdev. */ 
  219.  
  220. static int nextOpenID = 0;        /* Identifier for next pdev
  221.                        open by a client. */
  222.  
  223.  
  224.  
  225. List_Links openStreamListHdr;     /* List of open pdevs. */
  226. List_Links *openStreamList;     /* Pointer to list, used in calls. */
  227.  
  228. int migPdev_Debug = 0;
  229.  
  230.  
  231.  
  232.  
  233. /*
  234.  *----------------------------------------------------------------------
  235.  *
  236.  * MigPdev_Init --
  237.  *
  238.  *    Initialize data structures for this module.
  239.  *
  240.  * Results:
  241.  *    None.
  242.  *
  243.  * Side effects:
  244.  *    Open stream list is set up.
  245.  *
  246.  *----------------------------------------------------------------------
  247.  */
  248.  
  249. void
  250. MigPdev_Init()
  251. {
  252.  
  253.     openStreamList = &openStreamListHdr;
  254.     List_Init(openStreamList);
  255.     if (migPdev_Debug > 5) {
  256.     pdev_Trace = 1;
  257.     }
  258. }
  259.     
  260.  
  261. /*
  262.  *----------------------------------------------------------------------
  263.  *
  264.  * MigPdev_OpenMaster --
  265.  *
  266.  *    Set up the master end of a pseudo-device.  This can be either
  267.  *     the host-specific pdev or the global pdev, as specified by the
  268.  *    global variable migd_GlobalMaster.
  269.  *
  270.  * Results:
  271.  *    0 for successful completion, -1 for error.
  272.  *
  273.  * Side effects:
  274.  *    Opens pseudo-device as master.
  275.  *
  276.  *----------------------------------------------------------------------
  277.  */
  278.  
  279. int
  280. MigPdev_OpenMaster()
  281. {
  282.     struct stat atts;
  283.     
  284.     if (migPdev_Debug > 1) {
  285.     PRINT_PID;
  286.     fprintf(stderr, "MigPdev_OpenMaster -\n");
  287.     }
  288.  
  289.     if (migd_GlobalMaster) {
  290.     pdevName = migd_GlobalPdevName;
  291.     } else {
  292.     pdevName = migd_LocalPdevName;
  293.     }
  294.     
  295.     /*
  296.      * Open pdev.  If it's the global pdev and we can't open it, then
  297.      * presumably someone else beat us to it.  That's fine, let
  298.      * him handle it.  In any case, punt the error to our caller.
  299.      */
  300.     if (migPdev_Debug > 2) {
  301.     PRINT_PID;
  302.     fprintf(stderr, "MigPdev_OpenMaster - Open %s\n", pdevName);
  303.     }
  304. #ifdef notdef
  305.     pdev_Trace = 0;
  306. #endif
  307.     /*
  308.      * If we're opening the local pdev, and we've gotten this far, we
  309.      * know the global master recognizes us as the only daemon on this
  310.      * host.  Therefore, ensure against leftover masters by removing the
  311.      * pdev in case it already exists.  Note that statting the file
  312.      * may result in an error even though it actually exists, due to
  313.      * trying to get attributes associated with a nonexistent pdev master.
  314.      */
  315.     if (!migd_GlobalMaster) {
  316.     if (migPdev_Debug > 0 && stat(pdevName, &atts) == 0) {
  317.         fprintf(stderr, "Warning: removing leftover pdev %s.\n",
  318.            pdevName);
  319.     }
  320.     (void) unlink(pdevName);
  321.     }
  322.     pdev = Pdev_Open(pdevName, NULL, 0, 0, &service, NULL);
  323.     if (pdev == NULL) {
  324.     if (migPdev_Debug > 0) {
  325.         PRINT_PID;
  326.         fprintf(stderr, "MigPdev_OpenMaster: %s\n", pdev_ErrorMsg);
  327.     }
  328.     errno = ENODEV;
  329.     return (-1);
  330.     }
  331.  
  332.     if (migPdev_Debug > 1) {
  333.     PRINT_PID;
  334.     fprintf(stderr, "MigPdev_OpenMaster - completed successfully\n");
  335.     }
  336.  
  337.     return (0);
  338. }
  339.  
  340.  
  341. /*
  342.  *----------------------------------------------------------------------
  343.  *
  344.  * MigPdev_End --
  345.  *
  346.  *    Terminate service of the master end of the pdev.
  347.  *
  348.  * Results:
  349.  *    None.
  350.  *
  351.  * Side effects:
  352.  *    The pdev is removed and closed.
  353.  *
  354.  *----------------------------------------------------------------------
  355.  */
  356.  
  357. void
  358. MigPdev_End()
  359. {
  360.     int status;
  361.  
  362.     if (migPdev_Debug > 2) {
  363.     PRINT_PID;
  364.     fprintf(stderr, "MigPdev_End -\n");
  365.     }
  366.  
  367.     Pdev_Close(pdev);
  368.     pdev = NULL;
  369.  
  370.     status = unlink(pdevName);
  371.     if (status == -1) {
  372.     SYSLOG2(LOG_WARNING, "couldn't remove %s: %s\n",
  373.            pdevName, strerror(errno));
  374.     }
  375. }
  376.  
  377.  
  378. /*
  379.  *----------------------------------------------------------------------
  380.  *
  381.  * MigPdev_Stat --
  382.  *
  383.  *    Perform an fstat on the descriptor associated with the pdev we
  384.  *     are controlling.  .... OBSOLETE (never used)
  385.  *
  386.  * Results:
  387.  *    On error, -1 is returned and errno is set to the error returned
  388.  *    by fstat; else 0 is returned.
  389.  *
  390.  * Side effects:
  391.  *    None.
  392.  *
  393.  *----------------------------------------------------------------------
  394.  */
  395.  
  396. #ifdef 0 
  397. int
  398. MigPdev_Stat(attsPtr)
  399.     struct stat *attsPtr;
  400. {
  401.     int stream = Pdev_GetStreamID(pdev);
  402.     
  403.     if (migPdev_Debug > 2) {
  404.     PRINT_PID;
  405.     fprintf(stderr, "MigPdev_Stat -\n");
  406.     }
  407.     return(fstat(stream, attsPtr));
  408. }
  409. #endif
  410.  
  411.  
  412. /*
  413.  *----------------------------------------------------------------------
  414.  *
  415.  * SendSignal --
  416.  *
  417.  *    Send a signal over a stream.  Only used for signalling other
  418.  *    daemons upon normal master termination (for debugging).
  419.  *
  420.  * Results:
  421.  *    0 is returned, since we don't want to stop partway through.
  422.  *
  423.  * Side effects:
  424.  *    None.
  425.  *
  426.  *----------------------------------------------------------------------
  427.  */
  428.  
  429.  
  430. static int 
  431. SendSignal(streamPtr, clientData)
  432.     Pdev_Stream *streamPtr;    /* Pdev stream, containing streamID */
  433.     ClientData clientData;    /* Signal to send, as a ClientData */
  434. {
  435. #ifdef USE_PDEV_SIGNALS
  436.     Pdev_Signal sig;
  437. #endif /* USE_PDEV_SIGNALS */
  438.     int status;
  439.     Migd_OpenStreamInfo *cltPtr =
  440.     (Migd_OpenStreamInfo *) streamPtr->clientData;
  441.  
  442.     if (cltPtr->type != MIGD_DAEMON) {
  443.     return(0);
  444.     }
  445.     if (migPdev_Debug > 3) {
  446.     PRINT_PID;
  447.     fprintf(stderr, "SendSignal - sending signal to process %x\n",
  448.            cltPtr->processID);
  449.     }
  450.  
  451. #ifdef USE_PDEV_SIGNALS
  452.     sig.signal = (unsigned int) clientData;
  453.     sig.code = 0;
  454.     status = Fs_IOControl(streamPtr->streamID, IOC_PDEV_SIGNAL_OWNER,
  455.             sizeof(Pdev_Signal), (char *) &sig, 0, (char *) NULL);
  456. #else /* USE_PDEV_SIGNALS */
  457.     status = Sig_Send((unsigned int) clientData, cltPtr->processID, 0);
  458. #endif /* USE_PDEV_SIGNALS */
  459.     if (status != SUCCESS && migPdev_Debug > 0) {
  460.     PRINT_PID;
  461.     fprintf(stderr, "SendSignal: error sending signal to process %x: %s\n",
  462.            cltPtr->processID, Stat_GetMsg(status));
  463.     }
  464.     return(0);
  465. }
  466.  
  467.  
  468. /*
  469.  *----------------------------------------------------------------------
  470.  *
  471.  * MigPdev_SignalClients --
  472.  *
  473.  *    Send a signal to all clients.
  474.  *
  475.  * Results:
  476.  *    None.
  477.  *
  478.  * Side effects:
  479.  *    None.
  480.  *
  481.  *----------------------------------------------------------------------
  482.  */
  483.  
  484. void
  485. MigPdev_SignalClients(sig)
  486.     int sig;            /* Signal to send. */
  487. {
  488.     if (migPdev_Debug > 2) {
  489.     PRINT_PID;
  490.     fprintf(stderr, "MigPdev_SignalClients -\n");
  491.     }
  492.  
  493.     (void) Pdev_EnumStreams(pdev, SendSignal, (ClientData) sig);
  494. }
  495.  
  496. /*
  497.  *----------------------------------------------------------------------
  498.  *
  499.  * MigPdev_MakeReady --
  500.  *
  501.  *    Make a pdev stream readable, so someone selecting on it
  502.  *    will know to do an ioctl.  The ClientData is either NULL or
  503.  *    a function to determine whether to make this stream selectable.
  504.  *
  505.  * Results:
  506.  *    If an error occurs during the ioctl, then that error is returned,
  507.  *    else 0.
  508.  *
  509.  * Side effects:
  510.  *    The stream is marked.
  511.  *
  512.  *----------------------------------------------------------------------
  513.  */
  514.  
  515.  
  516. int 
  517. MigPdev_MakeReady(streamPtr, clientData)
  518.     Pdev_Stream *streamPtr;    /* Pdev stream, containing streamID */
  519.     ClientData clientData;    /* A function for selection, or NULL. */
  520. {
  521.     int (*func)();
  522.     int status;
  523.     Migd_OpenStreamInfo *cltPtr = (Migd_OpenStreamInfo *) streamPtr->clientData;
  524.  
  525.     func = (int (*) ()) clientData;
  526.     if (func != (int (*) ()) NULL) {
  527.     if (!(*func)(cltPtr)) {
  528.         return(0);
  529.     }
  530.     }
  531.     cltPtr->defaultSelBits |= FS_READ;
  532.     status = Fs_IOControl(streamPtr->streamID, IOC_PDEV_READY, sizeof(int),
  533.             (char *) &cltPtr->defaultSelBits, 0, (char *) NULL);
  534.     /*
  535.      * Note any errors, but only return non-zero status if we had
  536.      * no selection function (hence were notifying a particular
  537.      * client rather than a bunch at once).
  538.      */
  539.     if (status != 0) {
  540.     if (migPdev_Debug > 0) {
  541.         PRINT_PID;
  542.         fprintf(stderr, "Error making stream selectable for client %x: %s\n",
  543.            cltPtr->processID, Stat_GetMsg(status));
  544.     }
  545.     if (func != (int (*) ()) NULL) {
  546.         return(0);
  547.     }
  548.     return(status);
  549.     }
  550.     return(0);
  551. }
  552.  
  553.  
  554. /*
  555.  *----------------------------------------------------------------------
  556.  *
  557.  * DaemonSelectPredicate --
  558.  *
  559.  *    Selection predicate to just get clients that are daemons.
  560.  *
  561.  * Results:
  562.  *    1 if a daemon, 0 otherwise.
  563.  *
  564.  * Side effects:
  565.  *    None.
  566.  *
  567.  *----------------------------------------------------------------------
  568.  */
  569.  
  570. static int
  571. DaemonSelectPredicate(cltPtr)
  572.     Migd_OpenStreamInfo *cltPtr;
  573. {
  574.     if (cltPtr->type == MIGD_DAEMON) {
  575.     return(Global_IsHostUp(cltPtr->host));
  576.     } else {
  577.     return(0);
  578.     }
  579. }
  580.  
  581. /*
  582.  *----------------------------------------------------------------------
  583.  *
  584.  * MigPdev_NotifyDaemons --
  585.  *
  586.  *    Make migration daemons exceptable.  (To notify a particular
  587.  *    client, use MigPdev_MakeReady directly).
  588.  *
  589.  * Results:
  590.  *    None.
  591.  *
  592.  * Side effects:
  593.  *    None.
  594.  *
  595.  *----------------------------------------------------------------------
  596.  */
  597.  
  598. void
  599. MigPdev_NotifyDaemons()
  600. {
  601.  
  602.     if (migPdev_Debug > 2) {
  603.     PRINT_PID;
  604.     fprintf(stderr, "MigPdev_NotifyDaemons -\n");
  605.     }
  606.  
  607.     (void) Pdev_EnumStreams(pdev, MigPdev_MakeReady,
  608.                 (ClientData) DaemonSelectPredicate);
  609. }
  610.  
  611. /*
  612.  *----------------------------------------------------------------------
  613.  *
  614.  * PdevOpen --
  615.  *
  616.  *    Service an open request for the pdev.
  617.  *
  618.  * Results:
  619.  *    0, or an error condition.
  620.  *
  621.  * Side effects:
  622.  *    None.
  623.  *
  624.  *----------------------------------------------------------------------
  625.  */
  626.  
  627. /* ARGSUSED */
  628. static int
  629. PdevOpen(data, streamPtr, buff, flags, processID, host, user, selPtr)
  630.     ClientData data;        /* Ignored. */
  631.     Pdev_Stream *streamPtr;    /* Information for the stream. */
  632.     char *buff;            /* Ignored */
  633.     int flags;            /* Flags passed to Fs_Open. */
  634.     int processID;        /* Id of process doing open. */
  635.     int host;            /* Host on which opened. */
  636.     int user;            /* Userid of opener. */
  637.     int *selPtr;        /* Bits for Fs_Select. */
  638. {
  639.     Migd_OpenStreamInfo *cltPtr;
  640.  
  641.     if (migPdev_Debug > 2) {
  642.     PRINT_PID;
  643.     fprintf(stderr, "PdevOpen - request from %d:%x\n", host, processID);
  644.     }
  645.  
  646.     if (migd_Quit) {
  647.     if (migPdev_Debug > 0) {
  648.         PRINT_PID;
  649.         fprintf(stderr,
  650.            "PdevOpen - can't handle request from %d:%x because we are shutting down.\n",
  651.            host, processID);
  652.     }
  653.     return(ESHUTDOWN);
  654.     }
  655.     
  656.     /* Check valid open flags */
  657.     flags &= FS_USER_FLAGS;
  658.     if (flags & ~(FS_WRITE | FS_READ)) {
  659.     if (migPdev_Debug > 0) {
  660.         PRINT_PID;
  661.         fprintf(stderr, "PdevOpen - bad flags %x\n", flags);
  662.     }
  663.     return(EACCES);
  664.     }
  665.  
  666.     cltPtr = mnew(Migd_OpenStreamInfo);
  667.     bzero((char *) cltPtr, sizeof(Migd_OpenStreamInfo));
  668.     cltPtr->streamPtr = streamPtr;
  669.     cltPtr->user = user;
  670.     cltPtr->host = host;
  671.     cltPtr->processID = processID;
  672.     cltPtr->openID = nextOpenID;
  673.     /*
  674.      * By default, processes can't read or write the pdev, they must
  675.      * use ioctls.  They can use an ioctl to register a long-term
  676.      * interest, such as if they're a loadavg daemon or a load widget,
  677.      * but until then the default is not to be able to select on this
  678.      * stream.  (In addition, they can select on the stream and be
  679.      * told it's readable if there's a change in status, but again,
  680.      * it's unreadable by default until that happens.)  This default
  681.      * value is used to make it easy for routines to reset the select
  682.      * bits as appropriate.
  683.      */
  684.     if (migd_GlobalMaster) {
  685.     cltPtr->defaultSelBits = 0;
  686.     cltPtr->type = ((user == 0) && (flags & FS_WRITE)) ?
  687.         MIGD_DAEMON : MIGD_USER;
  688.     } else {
  689.     cltPtr->defaultSelBits = FS_READ;
  690.     cltPtr->type = MIGD_LOCAL;
  691.     }
  692.     nextOpenID++;
  693.     streamPtr->clientData = (ClientData) cltPtr;
  694.     List_Init(&cltPtr->currentRequests);
  695.     List_Init(&cltPtr->messages);
  696.     List_InitElement(&cltPtr->nextStream);
  697.     List_Insert((List_Links *)cltPtr, LIST_ATREAR(openStreamList));
  698.     cltPtr->waitPtr = (Migd_WaitList *) NULL;
  699.     
  700.     *selPtr = cltPtr->defaultSelBits;
  701.  
  702.     if (migPdev_Debug > 3) {
  703.     PRINT_PID;
  704.     fprintf(stderr, "PdevOpen - returning status 0\n");
  705.     }
  706.  
  707.     return(0);
  708. }
  709.  
  710.  
  711. /*
  712.  *----------------------------------------------------------------------
  713.  *
  714.  * PdevClose --
  715.  *
  716.  *    Service a close request for the pdev.  Clean up state, either
  717.  *     marking a host as down if the daemon on that host closed its
  718.  *    connection, or freeing hosts used by a client if it closes the
  719.  *    connection without freeing them first.
  720.  *
  721.  * Results:
  722.  *    0, or an error condition.
  723.  *
  724.  * Side effects:
  725.  *    None.
  726.  *
  727.  *----------------------------------------------------------------------
  728.  */
  729.  
  730. static int
  731. PdevClose(streamPtr)
  732.     Pdev_Stream *streamPtr;    /* Information for the stream */
  733. {
  734.     Migd_OpenStreamInfo *cltPtr;
  735.  
  736.  
  737.     cltPtr = (Migd_OpenStreamInfo *) streamPtr->clientData;
  738.     if (cltPtr == (Migd_OpenStreamInfo *) NULL) {
  739.     /*
  740.      * Stream wasn't fully opened -- if, for example, we were quitting
  741.      * at the time.
  742.      */
  743.     return(0);
  744.     }
  745.  
  746.     if (migPdev_Debug > 3) {
  747.     PRINT_PID;
  748.     fprintf(stderr, "PdevClose - pid %x\n", cltPtr->processID);
  749.     }
  750.  
  751.     switch (cltPtr->type) {
  752.     case MIGD_DAEMON: {
  753.         if (migPdev_Debug > 1) {
  754.         PRINT_PID;
  755.         fprintf(stderr, "PdevClose - daemon %x on host %d exited\n",
  756.                cltPtr->processID, cltPtr->host);
  757.         }
  758.         (void) Global_HostDown(cltPtr->host, 1);
  759.         break;
  760.     }
  761.     case MIGD_USER: {
  762.         if (migPdev_Debug > 2) {
  763.         PRINT_PID;
  764.         fprintf(stderr, "PdevClose - process closed pdev\n");
  765.         }
  766.         if (migd_GlobalMaster) {
  767.         /*
  768.          * Clean up after the process, by releasing hosts and
  769.          * recording statistics.
  770.          */
  771.         (void) Global_Done(cltPtr, MIG_ALL_HOSTS, 1);
  772.         }
  773.         break;
  774.     }
  775.     case MIGD_CLOSED: 
  776.     case MIGD_NEW: {
  777.         if (migPdev_Debug > 0) {
  778.         PRINT_PID;
  779.         fprintf(stderr,
  780.                "PdevClose - never heard from process %x, or connection is unusable.\n",
  781.                cltPtr->processID);
  782.         }
  783.         break;
  784.     }
  785.     case MIGD_LOCAL: {
  786.         if (migPdev_Debug > 2) {
  787.         PRINT_PID;
  788.         fprintf(stderr,
  789.                "PdevClose - local process %x exited.\n",
  790.                cltPtr->processID);
  791.         }
  792.         break;
  793.     default: {
  794.         PRINT_PID;
  795.         fprintf(stderr,
  796.             "PdevClose - bad type (%d) for client type.\n",
  797.             (int) cltPtr->type);
  798.         }
  799.         break;
  800.     }
  801.     }
  802.     
  803.     List_Remove((List_Links *)cltPtr);
  804.     free((Address) cltPtr);
  805.     return (0);
  806. }
  807.  
  808.  
  809. /*
  810.  *----------------------------------------------------------------------
  811.  *
  812.  * PdevRead --
  813.  *
  814.  *    Service a read request for the pdev.  This is permitted when a
  815.  *    process wants the load vector for its own host, and talks to
  816.  *    its daemon directly.  The master daemon doesn't service read
  817.  *    requests; requests for load go through the ioctl interface, which
  818.  *    also deals with byte swapping.  Note: we don't check the hostID
  819.  *     of the requester, since after all the hostID could be a physical
  820.  *    host that's different from us but the same byte order, but
  821.  *    if someone on a different architecture tries to read our structure
  822.  *    they may get garbage.
  823.  * 
  824.  * Results:
  825.  *    0 for success, EINVAL is returned if we're not the local daemon
  826.  *    or the read isn't at least the size of a Mig_Info structure.  
  827.  *
  828.  * Side effects:
  829.  *    None.
  830.  *
  831.  *----------------------------------------------------------------------
  832.  */
  833. /* ARGSUSED */
  834. static int
  835. PdevRead(streamPtr, readPtr, freeItPtr, selectBitsPtr, sigPtr)
  836.     Pdev_Stream *streamPtr;    /* Service stream the client specified in its
  837.                  * kernel call. */
  838.     Pdev_RWParam *readPtr;    /* Read parameter block.  Indicates size,
  839.                  * buffer, plus various IDs */
  840.     Boolean *freeItPtr;        /* Not used here. */
  841.     int *selectBitsPtr;        /* Store new select state of stream here. */
  842.     Pdev_Signal *sigPtr;    /* Signal information for returning signal. */
  843. {
  844.     Migd_OpenStreamInfo *cltPtr;
  845.  
  846.     cltPtr = (Migd_OpenStreamInfo *) streamPtr->clientData;
  847.     *selectBitsPtr = cltPtr->defaultSelBits;
  848.  
  849.     if (migPdev_Debug > 3) {
  850.     PRINT_PID;
  851.     fprintf(stderr, "PdevRead - request from %d:%x\n",
  852.            cltPtr->host, cltPtr->processID);
  853.     }
  854.     if (migd_Quit) {
  855.     sigPtr->signal = SIG_TERM;
  856.     }
  857.     if (migd_GlobalMaster) {
  858.     /*
  859.      * Wrong interface to communicate with the global master.
  860.      */
  861.     return (EINVAL);
  862.     }
  863.     if (readPtr->length < sizeof(Mig_Info)) {
  864.     if (migPdev_Debug > 0) {
  865.         PRINT_PID;
  866.         fprintf(stderr, "PdevRead - short read from %d:%x\n",
  867.            cltPtr->host, cltPtr->processID);
  868.     }
  869.     return(EINVAL);
  870.     }
  871.  
  872.     Migd_GetLocalLoad(readPtr->buffer);
  873.     readPtr->length = sizeof(Mig_Info);
  874.     return (0);
  875. }
  876.  
  877.  
  878. /*
  879.  *----------------------------------------------------------------------
  880.  *
  881.  * PdevWrite --
  882.  *
  883.  *    Service a write request for the pdev.  Write requests can be from
  884.  *     daemons, telling us a new load vector, or from clients, requesting
  885.  *    or returning one or more hosts.
  886.  *
  887.  * Results:
  888.  *    An error status, or 0 for success, is returned.
  889.  *
  890.  * Side effects:
  891.  *    None.
  892.  *
  893.  *----------------------------------------------------------------------
  894.  */
  895.  
  896. /* ARGSUSED */
  897. static int
  898. PdevWrite(streamPtr, async, writePtr, selectBitsPtr, sigPtr)
  899.     Pdev_Stream *streamPtr;    /* Service stream the client specified in its
  900.                  * kernel call. */
  901.     int async;            /* Non-zero means this is an asynchronous
  902.                  * write request. */
  903.     Pdev_RWParam *writePtr;    /* Write parameter block.  Indicates size,
  904.                  * offset, and buffer, among other things */
  905.     int *selectBitsPtr;        /* Just set to default. */
  906.     Pdev_Signal *sigPtr;    /* Signal to return, if any */
  907. {
  908.     Migd_OpenStreamInfo *cltPtr;
  909.     Mig_LoadVector loadVec;
  910.     Mig_LoadVector *loadPtr;
  911.     int status;
  912.     int inBufSize;
  913.     int outBufSize;
  914.  
  915.     cltPtr = (Migd_OpenStreamInfo *) streamPtr->clientData;
  916.  
  917.     if (migPdev_Debug > 3) {
  918.     PRINT_PID;
  919.     fprintf(stderr, "PdevWrite - packet from %d:%x\n", cltPtr->host,
  920.            cltPtr->processID);
  921.     }
  922.  
  923.     if (migd_Quit) {
  924.     sigPtr->signal = SIG_TERM;
  925.     }
  926.  
  927.     *selectBitsPtr = cltPtr->defaultSelBits;
  928.  
  929.     /*
  930.      * Process packet.
  931.      */
  932.     if (cltPtr->type != MIGD_DAEMON) {
  933.     if (migPdev_Debug > 1) {
  934.         PRINT_PID;
  935.         fprintf(stderr, "PdevWrite - got invalid write from %d:%x\n",
  936.            cltPtr->host, cltPtr->processID);
  937.     }
  938.     return(EPERM);
  939.     }
  940.     if (writePtr->length < sizeof(Mig_LoadVector)) {
  941.     if (migPdev_Debug > 0) {
  942.         SYSLOG3(LOG_WARNING,
  943.             "PdevWrite - short write from process %x: %d bytes of %d\n",
  944.             cltPtr->processID, writePtr->length,
  945.             sizeof(Mig_LoadVector));
  946.     }
  947.     return(EINVAL);
  948.     }
  949.     if (cltPtr->format != FMT_MY_FORMAT) {
  950.     inBufSize = writePtr->length;
  951.     outBufSize = sizeof(Mig_LoadVector);
  952.     status = Fmt_Convert(MIGD_LOADVEC_FMT,
  953.                  cltPtr->format,
  954.                  &inBufSize,
  955.                  writePtr->buffer,
  956.                  FMT_MY_FORMAT,
  957.                  &outBufSize,
  958.                  (char *) &loadVec);
  959.     if (status != FMT_OK || inBufSize != writePtr->length ||
  960.         outBufSize != sizeof(Mig_LoadVector)) {
  961.         PRINT_PID;
  962.         fprintf(stderr,
  963.            "PdevWrite - error swapping Mig_LoadVector structure, status = %d, swapped %d->%d of %d.\n",
  964.            status, inBufSize, outBufSize, sizeof(Mig_LoadVector));
  965.         return(EINVAL);
  966.     }
  967.     loadPtr = &loadVec;
  968.     } else {
  969.     loadPtr = (Mig_LoadVector *) writePtr->buffer;
  970.     }
  971.     status = Global_UpdateLoad(cltPtr, loadPtr);
  972.     if (status == 0 && !async) {
  973.     writePtr->length = sizeof(Mig_LoadVector);
  974.     }
  975.     
  976.     return(status);
  977. }
  978.  
  979.  
  980. /*
  981.  *----------------------------------------------------------------------
  982.  *
  983.  * PdevIoctl --
  984.  *
  985.  *    Basic entry point for communications with a server.  This
  986.  *    routine handles byte-swapping, but the real work is done
  987.  *    elsewhere.
  988.  *
  989.  * Results:
  990.  *    An error status, or 0 for success, is returned.
  991.  *
  992.  * Side effects:
  993.  *    Variable.
  994.  *
  995.  *----------------------------------------------------------------------
  996.  */
  997.  
  998. /* ARGSUSED */
  999. static int
  1000. PdevIoctl(streamPtr, ioctlPtr, selectBitsPtr, sigPtr)
  1001.     Pdev_Stream *streamPtr;    /* Service stream the client specified in its
  1002.                  * kernel call. */
  1003.     Pdev_IOCParam *ioctlPtr;    /* I/O control parameters */
  1004.     int *selectBitsPtr;        /* Store new select state here. */
  1005.     Pdev_Signal *sigPtr;    /* Returned signal, if any */
  1006. {
  1007.     Migd_OpenStreamInfo *cltPtr;
  1008.     int status;
  1009.     Address inBuffer;
  1010.     Address outBuffer;
  1011.     int bufSize;        /* Temporary holder for buffer size passed
  1012.                    to Fmt_Convert. */
  1013.     int inBufSize;        /* Size of the real input buffer. */
  1014.     int outBufSize;        /* Size of the real output buffer. */
  1015.     int command;
  1016.     char *swapBuffer = NULL;
  1017.     IoctlCallback *callbackPtr;
  1018.  
  1019.     cltPtr = (Migd_OpenStreamInfo *) streamPtr->clientData;
  1020.     command = ioctlPtr->command;
  1021.  
  1022.     if (migPdev_Debug > 3) {
  1023.     PRINT_PID;
  1024.     fprintf(stderr, "PdevIoctl - command %d from %x\n", command,
  1025.            cltPtr->processID);
  1026.     }
  1027.  
  1028.     /*
  1029.      * Set the selectBits ptr up front in case we return an error early on.
  1030.      */
  1031.     *selectBitsPtr = cltPtr->defaultSelBits;
  1032.     if (migd_Quit) {
  1033.     sigPtr->signal = SIG_TERM;
  1034.     }
  1035.  
  1036.     outBufSize = ioctlPtr->outBufSize;
  1037.     inBufSize = ioctlPtr->inBufSize;
  1038.  
  1039.     if (command == IOC_SET_OWNER) {
  1040.     return(0);
  1041.     }
  1042.     
  1043.     if (command <= IOC_GENERIC_LIMIT ||
  1044.     command > IOC_MIG_LASTCMD) {
  1045.     if (migPdev_Debug > 2) {
  1046.         SYSLOG2(LOG_WARNING, "undefined ioctl from %x: %d\n",
  1047.             cltPtr->processID, command);
  1048.     }
  1049.     return(EINVAL);
  1050.     }
  1051.  
  1052.     
  1053.  
  1054.     callbackPtr = &ioctlCallbacks[command - IOC_GENERIC_LIMIT - 1];
  1055.  
  1056.     /*
  1057.      * We need to swap if we're different byte orders.  We swap right now if
  1058.      * this ioctl takes input (inFmt is non-null).  We allocate extra
  1059.      * space for swapping later if outFmt is non-null. We save the format away
  1060.      * for use in read/write calls.
  1061.      */
  1062.     cltPtr->format = ioctlPtr->format;
  1063.     if (ioctlPtr->format != FMT_MY_FORMAT) {
  1064.     if (callbackPtr->inFmt != (char *) NULL) {
  1065.         bufSize = inBufSize;
  1066.         swapBuffer = Malloc(inBufSize);
  1067.         status = Fmt_Convert(callbackPtr->inFmt,
  1068.                  ioctlPtr->format,
  1069.                  &inBufSize,
  1070.                  ioctlPtr->inBuffer,
  1071.                  FMT_MY_FORMAT,
  1072.                  &bufSize,
  1073.                  swapBuffer);
  1074.         if (status != FMT_OK || inBufSize != ioctlPtr->inBufSize) {
  1075.         SYSLOG3(LOG_ERR,
  1076.                "PdevIoctl - error swapping ioctl input buffer, status = %d, swapped %d of %d.\n",
  1077.                status, inBufSize, ioctlPtr->inBufSize);
  1078.         free(swapBuffer);
  1079.         return(EINVAL);
  1080.         }
  1081.         inBuffer = swapBuffer;
  1082.         inBufSize = bufSize;
  1083.     } else {
  1084.         inBuffer = ioctlPtr->inBuffer;
  1085.     }
  1086.     if (callbackPtr->outFmt != (char *) NULL) {
  1087.         outBuffer = Malloc(outBufSize);
  1088.     } else {
  1089.         outBuffer = ioctlPtr->outBuffer;
  1090.     }
  1091.     } else {
  1092.     inBuffer = ioctlPtr->inBuffer;
  1093.     outBuffer = ioctlPtr->outBuffer;
  1094.     }
  1095.     
  1096.  
  1097.     status = (*callbackPtr->routine)
  1098.     (cltPtr, ioctlPtr->command, inBuffer, inBufSize, outBuffer,
  1099.      &outBufSize);
  1100.  
  1101. #ifdef lint
  1102.     status = Global_GetLoadInfo(cltPtr, ioctlPtr->command, inBuffer,
  1103.                 inBufSize, outBuffer, &outBufSize);
  1104.     status = Global_GetIdle(cltPtr, ioctlPtr->command, inBuffer, inBufSize,
  1105.                 outBuffer, &outBufSize);
  1106.     status = Global_DoneIoctl(cltPtr, ioctlPtr->command, inBuffer, inBufSize,
  1107.                  outBuffer, &outBufSize);
  1108.     status = Global_RemoveHost(cltPtr, ioctlPtr->command, inBuffer, inBufSize,
  1109.                    outBuffer, &outBufSize);
  1110.     status = Global_HostUp(cltPtr, ioctlPtr->command, inBuffer, inBufSize,
  1111.                    outBuffer, &outBufSize);
  1112.     status = Global_ChangeState(cltPtr, ioctlPtr->command, inBuffer, inBufSize,
  1113.                    outBuffer, &outBufSize);
  1114.     status = Global_GetStats(cltPtr, ioctlPtr->command, inBuffer, inBufSize,
  1115.                    outBuffer, &outBufSize);
  1116. #endif /* lint */
  1117.  
  1118.     if (status == 0) {
  1119.     /*
  1120.      * This time we need to swap if we're different byte orders and if
  1121.      * this ioctl returns output (outFmt is non-null).
  1122.      */
  1123.     if (ioctlPtr->format != FMT_MY_FORMAT &&
  1124.         callbackPtr->outFmt != (char *) NULL) {
  1125.         int origSize;
  1126.         
  1127.         bufSize = outBufSize;
  1128.         origSize = outBufSize;
  1129.         status = Fmt_Convert(callbackPtr->outFmt,
  1130.                  FMT_MY_FORMAT,
  1131.                  &bufSize,
  1132.                  outBuffer,
  1133.                  ioctlPtr->format,
  1134.                  &outBufSize,
  1135.                  ioctlPtr->outBuffer);
  1136.         if (status != FMT_OK || bufSize != origSize) {
  1137.         SYSLOG3(LOG_ERR,
  1138.                "PdevIoctl - error swapping ioctl output buffer, status = %d, swapped %d of %d.\n",
  1139.                status, bufSize, origSize);
  1140.         status = EINVAL;
  1141.         }
  1142.     }
  1143.     }
  1144.     /*
  1145.      * Free up extra buffers.
  1146.      */
  1147.     if (inBuffer != ioctlPtr->inBuffer) {
  1148.     free(inBuffer);
  1149.     }
  1150.     if (outBuffer != ioctlPtr->outBuffer) {
  1151.     free(outBuffer);
  1152.     }
  1153.  
  1154.     /*
  1155.      * Reset the selectBits ptr based on current value.
  1156.      */
  1157.     *selectBitsPtr = cltPtr->defaultSelBits;
  1158.  
  1159.     /*
  1160.      * Return a unix status since that's what pdev expects.  It will
  1161.      * convert to a sprite value if needed.
  1162.      */
  1163.     return (status);
  1164. }
  1165.  
  1166.  
  1167. /*
  1168.  *----------------------------------------------------------------------
  1169.  *
  1170.  * MigPdev_CloseAllStreams --
  1171.  *
  1172.  *    Close all open client streams, and the stream for any existing
  1173.  *    pdev master.  This occurs when we fork a process
  1174.  *     to become the new global master: the child closes its streams.
  1175.  *
  1176.  * Results:
  1177.  *    None.
  1178.  *
  1179.  * Side effects:
  1180.  *    Memory for the client records is freed.
  1181.  *
  1182.  *----------------------------------------------------------------------
  1183.  */
  1184.  
  1185. void
  1186. MigPdev_CloseAllStreams()
  1187. {
  1188. #ifdef notdef
  1189.     List_Links *listPtr;
  1190.     Migd_OpenStreamInfo *cltPtr;
  1191.  
  1192.     while (!List_IsEmpty(openStreamList)) {
  1193.     listPtr = List_First(openStreamList);
  1194.     List_Remove(listPtr);
  1195.     cltPtr = (Migd_OpenStreamInfo *) listPtr;
  1196.     close(cltPtr->streamPtr->streamID);
  1197.     free(cltPtr);
  1198.     }
  1199. #endif
  1200.     if (pdev != (Pdev_Token) NULL) {
  1201.     Pdev_Close(pdev);
  1202.     }
  1203. }
  1204. @
  1205.  
  1206.  
  1207. 2.0
  1208. log
  1209. @Changing version numbers.
  1210. @
  1211. text
  1212. @d28 1
  1213. a28 1
  1214. static char rcsid[] = "$Header: /sprite/src/daemons/migd/RCS/migPdev.c,v 1.9 90/05/28 17:07:27 douglis Exp Locker: douglis $ SPRITE (Berkeley)";
  1215. d159 14
  1216. a172 6
  1217. *----------------------------------------------------------------------
  1218. * * MigPdev_Init -- * *    Initialize data structures for this module.  *
  1219. * Results: *    None.  * * Side effects: *    Open stream list is
  1220. set up.  *
  1221. *----------------------------------------------------------------------
  1222. */
  1223. d180 3
  1224. d621 1
  1225. a621 1
  1226.     List_InitElement((List_Links *) cltPtr);
  1227. d1113 1
  1228. d1116 1
  1229. a1116 2
  1230.     
  1231. #ifdef notdef
  1232. @
  1233.  
  1234.  
  1235. 1.9
  1236. log
  1237. @changed to use FMT_MY_FORMAT now that it exists.
  1238. @
  1239. text
  1240. @d28 1
  1241. a28 1
  1242. static char rcsid[] = "$Header: /sprite/src/daemons/migd/RCS/migPdev.c,v 1.8 90/05/02 12:31:27 douglis Exp Locker: douglis $ SPRITE (Berkeley)";
  1243. @
  1244.  
  1245.  
  1246. 1.8
  1247. log
  1248. @added comments
  1249. @
  1250. text
  1251. @d28 1
  1252. a28 1
  1253. static char rcsid[] = "$Header: /sprite/src/daemons/migd/RCS/migPdev.c,v 1.7 90/04/27 00:59:18 douglis Exp Locker: douglis $ SPRITE (Berkeley)";
  1254. d112 1
  1255. a112 1
  1256. #define MIGD_STATS_FMT "{w8{b12w49{w20}2}8}"
  1257. a137 2
  1258. int    myFormat = -1;            /* my byte order format, see fmt.h */
  1259.  
  1260. d172 1
  1261. a172 15
  1262.  
  1263.  
  1264.     /*
  1265.      * XXX hack city!
  1266.      */
  1267. #ifdef ds3100
  1268.     myFormat = FMT_MIPS_FORMAT;
  1269. #else 
  1270. #ifdef sun4    
  1271.     myFormat = FMT_SPARC_FORMAT;
  1272. #else
  1273.     myFormat = FMT_68K_FORMAT;
  1274. #endif    
  1275. #endif    
  1276. }
  1277. d847 1
  1278. a847 1
  1279.     if (migPdev_Debug > 0) {
  1280. d863 1
  1281. a863 1
  1282.     if (cltPtr->format != myFormat) {
  1283. d870 1
  1284. a870 1
  1285.                  myFormat,
  1286. d959 4
  1287. a962 2
  1288.     SYSLOG2(LOG_WARNING, "undefined ioctl from %x: %d\n",
  1289.         cltPtr->processID, command);
  1290. d977 1
  1291. a977 1
  1292.     if (ioctlPtr->format != myFormat) {
  1293. d985 1
  1294. a985 1
  1295.                  myFormat,
  1296. d992 1
  1297. d1037 1
  1298. a1037 1
  1299.     if (ioctlPtr->format != myFormat &&
  1300. d1044 1
  1301. a1044 1
  1302.                  myFormat,
  1303. @
  1304.  
  1305.  
  1306. 1.7
  1307. log
  1308. @changes for statistics gathering.
  1309. @
  1310. text
  1311. @d28 1
  1312. a28 1
  1313. static char rcsid[] = "$Header: /sprite/src/daemons/migd/RCS/migPdev.c,v 1.6 90/04/24 18:00:41 douglis Exp Locker: douglis $ SPRITE (Berkeley)";
  1314. d697 5
  1315. a701 1
  1316.         (void) Global_Done(cltPtr, MIG_ALL_HOSTS);
  1317. d1041 2
  1318. d1086 4
  1319. @
  1320.  
  1321.  
  1322. 1.6
  1323. log
  1324. @intermediate checkpoint
  1325. @
  1326. text
  1327. @d28 1
  1328. a28 1
  1329. static char rcsid[] = "$Header: /sprite/src/daemons/migd/RCS/migPdev.c,v 1.5 90/04/03 11:09:35 douglis Exp Locker: douglis $ SPRITE (Berkeley)";
  1330. d112 1
  1331. a112 1
  1332. #define MIGD_STATS_FMT "{w4}"
  1333. d161 6
  1334. a166 14
  1335.  *----------------------------------------------------------------------
  1336.  *
  1337.  * MigPdev_Init --
  1338.  *
  1339.  *    Initialize data structures for this module.
  1340.  *
  1341.  * Results:
  1342.  *    None.
  1343.  *
  1344.  * Side effects:
  1345.  *    Open stream list is set up.
  1346.  *
  1347.  *----------------------------------------------------------------------
  1348.  */
  1349. d314 1
  1350. a314 1
  1351.  *     are controlling.
  1352. d326 1
  1353. d329 1
  1354. a329 1
  1355.     struct stats *attsPtr;
  1356. d339 1
  1357. a451 1
  1358.     int val;
  1359. d597 1
  1360. a602 4
  1361.     cltPtr->numRequested = 0;
  1362.     cltPtr->numAssigned = 0;
  1363.     cltPtr->numInUse = 0;
  1364.     cltPtr->maxRequested = 0;
  1365. d666 1
  1366. d668 7
  1367. @
  1368.  
  1369.  
  1370. 1.5
  1371. log
  1372. @changed a syslog warning to an error file warning only.
  1373. @
  1374. text
  1375. @d28 1
  1376. a28 1
  1377. static char rcsid[] = "$Header: /sprite/src/daemons/migd/RCS/migPdev.c,v 1.4 90/03/14 12:49:57 douglis Exp Locker: douglis $ SPRITE (Berkeley)";
  1378. d135 1
  1379. d609 4
  1380. @
  1381.  
  1382.  
  1383. 1.4
  1384. log
  1385. @debugging info
  1386. @
  1387. text
  1388. @d28 1
  1389. a28 1
  1390. static char rcsid[] = "$Header: /sprite/src/daemons/migd/RCS/migPdev.c,v 1.3 90/03/12 13:45:47 douglis Exp Locker: douglis $ SPRITE (Berkeley)";
  1391. d254 1
  1392. a254 1
  1393.         SYSLOG1(LOG_INFO, "Warning: removing leftover pdev %s.\n",
  1394. @
  1395.  
  1396.  
  1397. 1.3
  1398. log
  1399. @print pid's before messages in global log file; print dates here and
  1400. there; open files in append mode; changed file names to be in admin
  1401. subdir.  [this is a recording. beep!]
  1402. @
  1403. text
  1404. @d28 1
  1405. a28 1
  1406. static char rcsid[] = "$Header: /sprite/src/daemons/migd/RCS/migPdev.c,v 1.2 90/02/28 10:50:24 douglis Exp Locker: douglis $ SPRITE (Berkeley)";
  1407. d478 2
  1408. a479 2
  1409.         fprintf(stderr, "Error making stream selectable for client %x\n",
  1410.            cltPtr->processID);
  1411. d682 2
  1412. a683 2
  1413.         fprintf(stderr, "PdevClose - daemon on host %d exited\n",
  1414.                cltPtr->host);
  1415. d952 1
  1416. a952 1
  1417.      * Seet the selectBits ptr up front in case we return an error early on.
  1418. d968 2
  1419. a969 1
  1420.     SYSLOG1(LOG_WARNING, "undefined ioctl: %d\n", command);
  1421. @
  1422.  
  1423.  
  1424. 1.2
  1425. log
  1426. @print msgs to both syslog & error log when appropriate.  remove the
  1427. pdev before opening it if it's the local pdev since the global daemon
  1428. has recognized process already.
  1429. @
  1430. text
  1431. @d28 1
  1432. a28 1
  1433. static char rcsid[] = "$Header: /sprite/src/daemons/migd/RCS/migPdev.c,v 1.1 90/02/15 19:19:06 douglis Exp Locker: douglis $ SPRITE (Berkeley)";
  1434. d222 1
  1435. d238 1
  1436. d253 1
  1437. a253 1
  1438.     if (migPdev_Debug > 0 && stat(pdevName, &atts)) {
  1439. d262 1
  1440. d270 1
  1441. d300 1
  1442. d340 1
  1443. d381 1
  1444. d395 1
  1445. d424 1
  1446. d477 1
  1447. d539 1
  1448. d578 1
  1449. d584 1
  1450. d596 1
  1451. d638 1
  1452. d674 1
  1453. d681 1
  1454. d690 1
  1455. d701 1
  1456. d710 1
  1457. d717 4
  1458. a720 3
  1459.         fprintf(stderr,
  1460.                "PdevClose - bad type (%d) for client type.\n",
  1461.                (int) cltPtr->type);
  1462. d773 1
  1463. d788 1
  1464. d841 1
  1465. d857 1
  1466. d884 1
  1467. d946 1
  1468. @
  1469.  
  1470.  
  1471. 1.1
  1472. log
  1473. @Initial revision
  1474. @
  1475. text
  1476. @d28 1
  1477. a28 1
  1478. static char rcsid[] = "$Header: /user2/douglis/pdev_mig/migd/RCS/migPdev.c,v 2.4 90/02/14 11:46:35 douglis Exp Locker: douglis $ SPRITE (Berkeley)";
  1479. d42 1
  1480. d44 1
  1481. d219 2
  1482. d242 15
  1483. d304 32
  1484. a335 2
  1485.     syslog(LOG_WARNING, "%s migd: couldn't remove %s: %s\n",
  1486.            migd_ProgName, pdevName, strerror(errno));
  1487. d337 1
  1488. d840 4
  1489. a843 2
  1490.         fprintf(stderr, "PdevWrite - short write from %d:%x\n",
  1491.            cltPtr->host, cltPtr->processID);
  1492. d870 1
  1493. a870 1
  1494.     writePtr->length = outBufSize;
  1495. d872 1
  1496. d941 1
  1497. a941 1
  1498.     syslog(LOG_WARNING, "%s: undefined ioctl: %d\n", migd_ProgName, command);
  1499. d968 1
  1500. a968 1
  1501.         syslog(LOG_ERR,
  1502. d1027 1
  1503. a1027 1
  1504.         syslog(LOG_ERR,
  1505. d1077 1
  1506. d1085 1
  1507. @
  1508.